//
//  UIBarButtonItem+Extensions.swift
//  微博
//
//  Created by 康智桐 on 2018/4/3.
//  Copyright © 2018年 Kk. All rights reserved.
//

import UIKit

//使用便利构造函数，减少控件的创建。
extension UIBarButtonItem{
    convenience init(title:String,fontSize:CGFloat = 16,target:AnyObject?,action:Selector,isBack:Bool = false) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack{
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue:0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for:.highlighted)
            
            btn.sizeToFit()

            
        }
        
        
        btn.addTarget(target, action:action, for: .touchUpInside)
        
        
        self.init(customView:btn)
    }
}
